package org.kgc.alanhealth.controller;

import org.kgc.alanhealth.entity.HospitalComments;
import org.kgc.alanhealth.service.CommentsService;
import org.kgc.alanhealth.service.impl.CommentsServiceImpl;
import org.kgc.alanhealth.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("comments")
@CrossOrigin(origins = "*")
public class CommentsController {
    @Autowired
    CommentsService commentsService;
    @RequestMapping("query")
    public Result  getComments() {
        List<HospitalComments> commentsList = commentsService.getHospitalComments();
        if(commentsList != null&&commentsList.size()!=0) {
            return Result.success(commentsList);
        }else {
            return Result.error("not find");
        }
    }
    @RequestMapping("queryByrelease")
    public Result  getCommentsByRelease() {
        List<HospitalComments> commentsList = commentsService.getAllByRelease();
        if(commentsList != null&&commentsList.size()!=0) {
            return Result.success(commentsList);
        }else {
            return Result.error("not find");
        }
    }
    @RequestMapping("queryByreply")
    public Result  getCommentsByReply() {
        List<HospitalComments> commentsList = commentsService.getAllByReply();
        if(commentsList != null&&commentsList.size()!=0) {
            return Result.success(commentsList);
        }else {
            return Result.error("not find");
        }
    }
    @RequestMapping ("insertAll")
    public Result insertAll(@RequestBody HospitalComments comments) {
            if (commentsService.insertAll(comments) > 0) {
                return Result.success("发布成功");
            } else {
                return Result.error("Insert failed");
            }
    }

    @RequestMapping("selectbyid")
    public Result selectbyid(Long id) {
        List<HospitalComments> commentsList = commentsService.selectByPrimaryKey(id);
        if (commentsList!=null){
            return Result.success(commentsList);
        }else{
            return Result.error("没有找到数据");
        }
    }
    @RequestMapping("selectbyidAll")
    public Result selectbyidAll(int id) {
        List<HospitalComments> commentsList = commentsService.selectAll(id);
        if (commentsList!=null){
            return Result.success(commentsList);
        }else{
            return Result.error("没有找到数据");
        }
    }
}
